package integration;

import java.io.File;
import java.io.FileReader;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import integration.beans.Promotion;

public class PromotionDAO {
	public Promotion lire(String fileName)
	{
		try{
			JAXBContext context = JAXBContext.newInstance("integration.beans");
			Unmarshaller decodeur = context.createUnmarshaller();

			//si validation
			SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.XML_NS_URI);
			Schema s = sf.newSchema(new File("promotion.xsd"));

			FileReader inputFile = new FileReader(fileName);
			Promotion p =(Promotion)decodeur.unmarshal(inputFile);
			return p;
		}
		catch(Exception e)
		{
		}
		return null;
	}
}